<template>
	<view class="bg-white" :style="{'padding-bottom': safeBottom +'px'}">
		<view class="flex" style="height: 90rpx;">
		  <view class="flex align-center justify-evenly" style="width: 300rpx;">
				<view v-if="type !='seckill'" class="flex flex-column align-center justify-between" style="width: 100rpx;" @click="collect">
					<image src="/static/index/dyBottomBuy/sc2.png" style="width: 40rpx;height: 40rpx;" v-if="!isCollect"></image>
					<image src="/static/index/dyBottomBuy/sc.png" style="width: 40rpx;height: 40rpx;" v-else></image>
					<uni-icons type="star-filled" size="22" color="#ffa300" v-else></uni-icons>
					<text class="u-font-24" >收藏</text>
				</view>
				<view class="position-relative" style="width: 100rpx;">
					<view class="flex flex-column align-center justify-between" @click="toCart">
						<image src="/static/index/dyBottomBuy/gwc.png" style="width: 40rpx;height: 40rpx;"></image>
						<text class="u-font-24" >购物车</text>
					</view>
					<!-- #ifndef APP-NVUE -->
					<u-badge absolute type="error" size="mini" :count="totalNum || totalGoods" :offset="[0,0]"></u-badge>
					<!-- #endif -->
					<!-- #ifdef APP-NVUE -->
					<view class="position-absolute right-0 top-0 rounded-15 main-bg-color" style="height: 30rpx;border: 1px solid var(--mainColor);">
						<text class="u-font-24 text-white u-p-x-5" style="line-height: 30rpx;">{{totalNum || totalGoods}}</text>
					</view>
					<!-- #endif -->
				</view>
				<view v-if="merchId != 0" class="flex flex-column align-center justify-between" style="width: 100rpx;" @click="toSupplier">
					<image src="/static/index/dyBottomBuy/dp.png" style="width: 40rpx;height: 40rpx;"></image>
					<text class="u-font-24">店铺</text>
				</view>
		  </view>
		  <view class="flex-1 flex font-weight-bold" style="width: 450rpx;" v-if="type == 'common'">
		    <text class="flex-1 text-center u-font-26 text-white" style="background-color: #ff8900;line-height: 90rpx;" @click="buy">加入购物车</text>
		    <text v-if="goodsType != 5" class="flex-1 text-center u-font-26 text-white" style="background-color: #fe572a;line-height: 90rpx;" @click="buy">立即购买</text>
		  </view>
			<view class="flex-1 flex font-weight-bold" style="width: 60%;" v-else-if="type == 'seckill'">
			  <view class="flex-1 flex align-center justify-center font text-white u-font-30" style="background-color: #d45643;" @click="seckill">立即抢购</view>
			</view>
		</view>
	</view>
	
</template>

<script>
	var safeBottom = uni.getSystemInfoSync().safeAreaInsets.bottom
	import { mapState } from "vuex";
	export default {
		name:"dy-bottom-buy",
		props: {
			merchId: {
				type: [String, Number],
				default: ''
			},
			type: {
				type: String,
				default: 'commom'
			},
			price: {
				type: String,
				default: ''
			},
			groupPrice: {
				type: String,
				default: ''
			},
			isCollect: {
				type: [String, Number],
				default: 0
			},
			goodsType:{
				type: String,
				default: ''
			},
			totalNum:{
				type: String,
				default:''
			}
		},
		data() {
			return {
				safeBottom: safeBottom
			};
		},
		computed: {
			...mapState('user', ['userCarts','totalGoods']),
		},
		methods: {
			buy() {
				this.$emit('buy')
			},
			toCart() {
				if(this.goodsType == 5){
					uni.navigateTo({
						url:'/pages/supplierPage/supplierIndex/supplierIndex?' +`id=${this.merchId}&type=1`
					})
					return
				}
				uni.switchTab({
					url: '/pages/tabbar/cart/cart'
				})
			},
			collect() {
				this.$emit('collect')
			},
			seckill() {
				this.$emit('seckill')
			},
			toSupplier() {
				uni.navigateTo({
					url:'/pages/supplierPage/supplierIndex/supplierIndex?' +`id=${this.merchId}&type=1`
				})
			}
		}
	}
</script>

<style lang="scss" scoped>

</style>
